package com.yvon.maple.service.msg.core.service.impl;

import com.google.common.collect.Sets;
import com.yvon.boot.mybatis.BaseServiceImpl;
import com.yvon.maple.service.msg.core.model.entity.ImContent;
import com.yvon.maple.service.msg.core.mapper.ImContentMapper;
import com.yvon.maple.service.msg.core.service.ImConsumerService;
import com.yvon.maple.service.msg.core.service.ImContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @author : Yvon
 * @since : 2021-08-26
 */
@Service
public class ImContentServiceImpl extends BaseServiceImpl<ImContent, ImContentMapper> implements ImContentService {

    @Autowired
    private ImConsumerService imConsumerService;

    @Override
    public boolean send(ImContent message, Set<String> consumers) {
        return save(message) && imConsumerService.save(message.getId(), consumers);
    }

    @Override
    public boolean send(ImContent message, String consumer) {
        return save(message) && imConsumerService.save(message.getId(), Sets.newHashSet(consumer));
    }

    @Override
    public long getUnReadCount(String username) {
        return baseMapper.getUnReadCount(username);
    }

    @Override
    public List<ImContent> selectUnRead(String username) {
        return baseMapper.selectUnRead(username);
    }
}
